import {Observable} from 'rxjs/Observable';

// generateData 对象
function generateData() {
    const people = [
        { name: 'David', age: 3, salary: 2000 },
        { name: 'Dav', age: 17, salary: 12000 },
        { name: 'Lomo', age: 20, salary: 16000 },
        { name: 'Dev', age: 20, salary: 10000 },
        { name: 'Amy', age: 7, salary: 34000 },
    ];

    return Observable.create(
        observer => {
            let i = 0;
            people.forEach( p => { 
                console.log('推送第 ' + (++i) + ' 条数据');
                observer.next(p)
            });
            observer.complete();
        }
    );
}

generateData().subscribe(
    // people => {
    //     console.log(people.name + '--' + people.age + '--' + people.salary);
    // },
    // error => { console.log(error); },
    // () => { console.log('消费完了.'); }
);